* Load dataset
use "replication data - table A24.dta", clear

log using "table A24.txt", text replace
log off

preserve

* drop observations before 1991 and observations with Islamists in power
keep if year > 1990
keep if execrel !=3 & gov1rel !=3


gen islamist_terror 	= lln_cyear_islamkill
gen nonislamist_terror 	= lln_cyear_nonislamkill

local isl_opp	"i.dpi_islam_opp"
local terror	"c.*islamist_terror"
local controls 	"ln_infant ln_oil polity2 change_polity2 muslim00 firstmp elec_violence nelda_kc legislative l5_internal_any coup_last5yr col_any ln_totalgdp ln_totaltrade"


******************************
* Table A24 - Models 1 and 2 *
******************************

reg critic  `isl_opp'##(`terror') , cl(ccode) 
est store tb24_m1

reg critic `controls'  `isl_opp'##(`terror') , cl(ccode) 
est store tb24_m2


**************************
* Table A24 - Models 3-6 *
**************************

replace islamist_terror = ln5_cyear_islamkill
replace nonislamist_terror = ln5_cyear_nonislamkill
local isl_opp	"i.dpi_islam_opp"
local terror	"c.*islamist_terror"
local ver		"5years"

reg critic  `isl_opp'##(`terror') , cl(ccode) 
est store tb24_m3

reg critic `controls'  `isl_opp'##(`terror') , cl(ccode) 
est store tb24_m4

* XTREG
xtreg critic `controls'  `isl_opp'##(`terror') , cl(ccode) fe
est store tb24_m5

xtreg critic `controls'  `isl_opp'##(`terror')##i.post911 , cl(ccode) fe
est store tb24_m6

log on
**************************
* Table A24 *
**************************

local controls "ln_infant ln_oilprod polity2 change_polity2 muslim00 firstmp elec_violence legislative l5_internal_any coup_last5yr nelda_kc col_any ln_totalgdp ln_totaltrade"
esttab tb24*, se noomit nobase varwidth(45) mtitle star(* 0.1 ** 0.05) stats(N r2_a) drop(`controls') compress label

log off

*************
* FIGURE A6 *
*************

replace islamist_terror = ln5_cyear_islamkill
replace nonislamist_terror = ln5_cyear_nonislamkill
local isl_opp	"i.dpi_islam_opp"
local terror	"c.*islamist_terror"

* Run the OLS model again
reg critic  `isl_opp'##(`terror') , cl(ccode) 
est store tb24_m3

sum *islamist_terror* if e(sample)==1


margins, dydx(dpi_islam_opp) at(nonislamist_terror=0 islamist_terror=(0(0.25)5.25))
marginsplot, recastci(rarea) scheme(plotplain) xtitle("log of Islamist Terrorist Killings")
graph export figureA6.pdf

log close
